/**
 * @author Aaron Berk
 *
 * @section LICENSE
 *
 * Copyright (c) 2010 ARM Limited
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @section DESCRIPTION
 *
 * IMU orientation filter developed by Sebastian Madgwick.
 *
 * Find more details about his paper here:
 *
 * http://code.google.com/p/imumargalgorithm30042010sohm/
 */

#ifndef IMU_FILTER_H
#define IMU_FILTER_H

/**
 * Includes
 */

/**
 * Defines
 */
#define PI 3.1415926536

/**
 * IMU orientation filter.

 class IMUfilter {

 public:

 /**
 * Constructor.
 *
 * Initializes filter variables.
 *
 * @param rate The rate at which the filter should be updated.
 * @param gyroscopeMeasurementError The error of the gyroscope in degrees
 *  per second. This used to calculate a tuning constant for the filter.
 *  Try changing this value if there are jittery readings, or they change
 *  too much or too fast when rotating the IMU.
 */
void imu_filter_init(float gyroscopeMeasurementError);

/**
 * Update the filter variables.
 *
 * @param w_x X-axis gyroscope reading in rad/s.
 * @param w_y Y-axis gyroscope reading in rad/s.
 * @param w_z Z-axis gyroscope reading in rad/s.
 * @param a_x X-axis accelerometer reading in m/s/s.
 * @param a_y Y-axis accelerometer reading in m/s/s.
 * @param a_z Z-axis accelerometer reading in m/s/s.
 */
void imu_filter_update(float w_x, float w_y, float w_z, float a_x, float a_y, float a_z);


void imu_filter_set_sample_rate(float rate);

/**
 * Compute the Euler angles based on the current filter data.
 */
void imu_filter_compute_euler(void);

/**
 * Get the current roll.
 *
 * @return The current roll angle in radians.
 */
float imu_filter_get_roll(void);

/**
 * Get the current pitch.
 *
 * @return The current pitch angle in radians.
 */
float imu_filter_get_pitch(void);

/**
 * Get the current yaw.
 *
 * @return The current yaw angle in radians.
 */
float imu_filter_get_yaw(void);

/**
 * Reset the filter.
 */
void imu_filter_reset(void);

#endif /* IMU_FILTER_H */
